package com.bree.erp.entity;

import java.util.Collection;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.NamedQueries;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

@NamedQueries({
	@NamedQuery(name = Project.QUERY_FIND_PROJECT_BY_CODE, 
				query = "SELECT p FROM Project p WHERE p.code = :code"),
	@NamedQuery(name = Project.QUERY_SELECT_ALL_PROJECT, 
				query = "SELECT p FROM Project p")
})
@Entity
public class Project implements CrudId<Long> {
	
	private static final long serialVersionUID = 1L;
	
	public static final String QUERY_FIND_PROJECT_BY_CODE = "findProjectByCode";
	public static final String QUERY_SELECT_ALL_PROJECT = "selectAllProject";
	private static final int COL_CODE_LEN = 15;
	private static final int COL_DESCRIPTION_LEN = 255;
	private static final int COL_JOBNUMBER_LEN = 10;
			
	@Id 
	@GeneratedValue(strategy=GenerationType.AUTO)
	private Long id;
	
	@Column(length=COL_CODE_LEN)
	private String code;
	@Column(length=COL_DESCRIPTION_LEN)
	private String description;
	
	@Column(length = 5)
	private String poNumberPrefix;

	@Column(length = COL_JOBNUMBER_LEN)
	private String jobNumber;
	
	@OneToMany(mappedBy="project")
	private Collection<PurchaseRequisition> purchaseRequisitions;
	
	@OneToOne
	private Warehouse defaultWarehouse;
	
	@Override
	public boolean equals(Object object) {
		
		if(this == object) {
			return true;
		}
		
		if(object instanceof Project) {
			Project that = (Project) object;
			return this.id != null && this.id.equals(that.id);
		}
		
		return false;
	}
	
	public String getDisplayString() {
		return this.code + " : " + this.description;
	}
	
	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}
	/**
	 * @return the code
	 */
	public String getCode() {
		return code;
	}
	/**
	 * @param code the code to set
	 */
	public void setCode(String code) {
		this.code = code;
	}
	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}
	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}
	/**
	 * @return the purchaseRequisitions
	 */
	public Collection<PurchaseRequisition> getPurchaseRequisitions() {
		return purchaseRequisitions;
	}
	/**
	 * @param purchaseRequisitions the purchaseRequisitions to set
	 */
	public void setPurchaseRequisitions(
			Collection<PurchaseRequisition> purchaseRequisitions) {
		this.purchaseRequisitions = purchaseRequisitions;
	}
	/**
	 * @return the defaultWarehouse
	 */
	public Warehouse getDefaultWarehouse() {
		return defaultWarehouse;
	}
	/**
	 * @param defaultWarehouse the defaultWarehouse to set
	 */
	public void setDefaultWarehouse(Warehouse defaultWarehouse) {
		this.defaultWarehouse = defaultWarehouse;
	}

	/**
	 * @return the poNumberPrefix
	 */
	public String getPoNumberPrefix() {
		return poNumberPrefix;
	}

	/**
	 * @param poNumberPrefix the poNumberPrefix to set
	 */
	public void setPoNumberPrefix(String poNumberPrefix) {
		this.poNumberPrefix = poNumberPrefix;
	}

	/**
	 * @return the jobNumber
	 */
	public String getJobNumber() {
		return jobNumber;
	}

	/**
	 * @param jobNumber the jobNumber to set
	 */
	public void setJobNumber(String jobNumber) {
		this.jobNumber = jobNumber;
	}
}
